/*
 * @Author: dfh
 * @Date: 2024-10-17 08:35:38
 * @LastEditors: dfh
 * @Modified By: dfh
 * @describe:
 */
import globals from "globals";
import pluginJs from "@eslint/js";
import tseslint from "typescript-eslint";
import pluginVue from "eslint-plugin-vue";
import prettierRecommended from "eslint-plugin-prettier/recommended";
import { createRequire } from "module";
const require = createRequire(import.meta.url);
const autoImportConfig = require("./.eslintrc-auto-import.json");

export default [
  // 1.检测文件格式
  { files: ["**/*.{js,mjs,cjs,ts,vue}"] },
  // 2.定义不同环境的全局变量
  {
    languageOptions: {
      globals: {
        ...globals.browser,
        ...globals.node,
        ...autoImportConfig.globals
      }
    }
  },
  // 3.js推荐规则
  pluginJs.configs.recommended,
  // 4.ts推荐规则
  ...tseslint.configs.recommended,
  // 5.vue推荐规则
  ...pluginVue.configs["flat/essential"],
  // 6.检测vue中的ts代码采用tsparser
  {
    files: ["**/*.vue"],
    languageOptions: { parserOptions: { parser: tseslint.parser } }
  },
  // 7.添加ignores选择
  { ignores: ["*.css", "*.jpg", "*.jpeg", "*.png", "*.gif", "*.d.ts"] },
  // 8.添加测试规则
  {
    rules: {
      //自定义规则
      "vue/multi-word-component-names": "off"
    }
  },
  prettierRecommended
];
